package com.mapapp.flutter_mapapp.widget;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.view.View;
import android.widget.TextView;

import com.mapapp.flutter_mapapp.R;

import razerdp.basepopup.BasePopupWindow;

public class ReplaceCacheDialog extends BasePopupWindow {

    private CardView cvEnsure;
    private CardView cvCancel;
    private TextView tvTips;

    private boolean isMergeHousehold;


    public ReplaceCacheDialog(Context context, boolean isMergeHousehold) {
        super(context);
        this.isMergeHousehold = isMergeHousehold;
        delayInit();
        init();
    }

    @Override
    public View onCreateContentView() {
        View view = createPopupById(R.layout.dialog_back);
        cvEnsure = view.findViewById(R.id.cv_ensure);
        cvCancel = view.findViewById(R.id.cv_cancel);
        tvTips = view.findViewById(R.id.tv_tips);
        return view;
    }

    private void init() {

        if (isMergeHousehold) {
            tvTips.setText("是否放弃之前的分户");
        } else {
            tvTips.setText("是否放弃之前的合户");
        }

        cvEnsure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick();
                }
                dismiss();
            }
        });

        cvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        cvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

    }

    public interface OnItemEnsureClickListener {
        void onClick();
    }

    private OnItemEnsureClickListener listener;

    public void setListener(OnItemEnsureClickListener listener) {
        this.listener = listener;
    }
}
